# Maintainer: Sarah Ottinger

_realname=pytest-mock
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.5.0
pkgrel=1
pkgdesc='Thin-wrapper around the mock package for easier use with py.test (mingw-w64)'
arch=('any')
url="https://github.com/pytest-dev/pytest-mock/"
license=('LGPL3')
depends=("${MINGW_PACKAGE_PREFIX}-python-pytest")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
source=("${_realname}-$pkgver.tar.gz::https://github.com/pytest-dev/pytest-mock/archive/v$pkgver.tar.gz")
sha256sums=('36b45039d5fc4086200c53242f59cd1f9f10ec6a9ada5c93f5d64fc2d4427b70')

export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-$pkgver" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
  --root="$PWD/tmp_install" --optimize=1 --skip-build || warning "Tests failed"
  PYTHONPATH="$PWD/tmp_install/${MINGW_PREFIX}/lib/python3.8/site-packages:$PYTHONPATH:$PWD/tests" ${MINGW_PREFIX}/bin/py.test || warning "Tests failed"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
